package org.yaac.server.egql.processor;

import static com.google.common.collect.Lists.newLinkedList;

import java.util.List;

import org.yaac.server.egql.evaluator.EvaluationResult;
import org.yaac.shared.file.FileDownloadPath;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 *	intermediate data, used for input / output of process context
 */
public class ProcessData {

	/**
	 * @author Max Zhu (thebbsky@gmail.com)
	 *
	 */
	public static interface ProcessDataRecord {
		/**
		 * @param name
		 * @return
		 */
		EvaluationResult lookup(String name);
		
		/**
		 * @return
		 */
		Iterable<EvaluationResult> asIterable();
		/**
		 * this is a special case used by Blob / Text editing
		 * 
		 * 
		 * @param index
		 * @return
		 */
		FileDownloadPath lookupFileReference(Integer index);
	}

	private List<ProcessDataRecord> records;
	
	public ProcessData() {
		records = newLinkedList();
	}

	public List<ProcessDataRecord> getRecords() {
		return records;
	}
	
	public ProcessData addRecord(ProcessDataRecord record) {
		this.records.add(record);
		return this;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((records == null) ? 0 : records.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProcessData other = (ProcessData) obj;
		if (records == null) {
			if (other.records != null)
				return false;
		} else if (!records.equals(other.records))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ProcessData [records=" + records + "]";
	}
}
